//
//  YWFansTableViewCell.m
//  聆听FM
//
//  Created by dllo on 16/6/18.
//  Copyright © 2016年 Dark. All rights reserved.
//

#import "YWFansTableViewCell.h"

@implementation YWFansTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.photoImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_photoImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_titleLabel];
        
        self.vImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_vImageView];
        
        self.voiceCountLabel = [[UILabel alloc] init];
        _voiceCountLabel.font = [UIFont systemFontOfSize:13];
        _voiceCountLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_voiceCountLabel];
        
        self.fansCountLabel = [[UILabel alloc] init];
        _fansCountLabel.font = [UIFont systemFontOfSize:13];
        _fansCountLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_fansCountLabel];
        
        self.ptitleLabel = [[UILabel alloc] init];
        _ptitleLabel.font = [UIFont systemFontOfSize:13];
        _ptitleLabel.textColor = [UIColor redColor];
        [self.contentView addSubview:_ptitleLabel];
        
        self.lineLabel = [[UILabel alloc] init];
        _lineLabel.backgroundColor = [UIColor colorWithWhite:0.737 alpha:1.000];
        [self.contentView addSubview:_lineLabel];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _photoImageView.frame = CGRectMake(15 * FITWIDTH, 10 * FITHEIGHT, 40 * FITWIDTH, 40 * FITWIDTH);
    _photoImageView.layer.cornerRadius = 20 * FITWIDTH;
    _photoImageView.layer.masksToBounds = YES;
    _titleLabel.frame = CGRectMake(_photoImageView.frame.origin.x + _photoImageView.bounds.size.width + 10 * FITWIDTH, 10 * FITHEIGHT, 10000, 25 * FITHEIGHT);
    [_titleLabel sizeToFit];
    _vImageView.frame = CGRectMake(_titleLabel.frame.origin.x + _titleLabel.bounds.size.width + 5 * FITWIDTH, 10 * FITHEIGHT, 17 * FITWIDTH, 17 * FITHEIGHT);
    _voiceCountLabel.frame = CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.origin.y + _titleLabel.bounds.size.height + 10 * FITHEIGHT, 10000, 20 * FITHEIGHT);
    [_voiceCountLabel sizeToFit];
    _fansCountLabel.frame = CGRectMake(_voiceCountLabel.frame.origin.x + _voiceCountLabel.bounds.size.width + 10 * FITWIDTH, _voiceCountLabel.frame.origin.y, 10000, 20 * FITHEIGHT);
    [_fansCountLabel sizeToFit];
    _ptitleLabel.frame = CGRectMake(_voiceCountLabel.frame.origin.x, _voiceCountLabel.frame.origin.y + _voiceCountLabel.bounds.size.height + 10 * FITHEIGHT, 10000, 20 * FITHEIGHT);
    [_ptitleLabel sizeToFit];
    _lineLabel.frame = CGRectMake(_ptitleLabel.frame.origin.x, self.bounds.size.height - 1, SCREENWIDTH - _ptitleLabel.frame.origin.x, 1);
}

- (void)setFansModel:(YWFansModel *)fansModel
{
    if (_fansModel != fansModel) {
        _fansModel = fansModel;
        [_photoImageView sd_setImageWithURL:[NSURL URLWithString:fansModel.smallLogo] placeholderImage:[UIImage sd_animatedGIFNamed:@"占位图"]];
        _titleLabel.text = fansModel.nickname;
        if (fansModel.isVerified == YES) {
            _vImageView.image = [UIImage imageNamed:@"V"];
        }
        _voiceCountLabel.text = [NSString stringWithFormat:@"声音 %ld", fansModel.tracks];
        NSInteger num = fansModel.followers;
        if (num < 10000) {
            _fansCountLabel.text = [NSString stringWithFormat:@"粉丝 %ld", num];
        }
        else
        {
            if (num % 10000 == 0) {
                _fansCountLabel.text = [NSString stringWithFormat:@"粉丝 %ld万", num / 10000];
            }
            else
            {
                _fansCountLabel.text = [NSString stringWithFormat:@"粉丝 %.1f万", num / 10000.0];
            }
        }
        _ptitleLabel.text = fansModel.ptitle;
    }
}

- (void)setSearchModel:(YWSearchModel *)searchModel
{
    if (_searchModel != searchModel) {
        _searchModel = searchModel;
        [_photoImageView sd_setImageWithURL:[NSURL URLWithString:searchModel.smallPic] placeholderImage:[UIImage sd_animatedGIFNamed:@"占位图"]];
        _titleLabel.text = searchModel.nickname;
        if (searchModel.isVerified == YES) {
            _vImageView.image = [UIImage imageNamed:@"V"];
        }
        _voiceCountLabel.text = [NSString stringWithFormat:@"声音 %ld", searchModel.tracks_counts];
        NSInteger num = searchModel.followers_counts;
        if (num < 10000) {
            _fansCountLabel.text = [NSString stringWithFormat:@"粉丝 %ld", num];
        }
        else
        {
            if (num % 10000 == 0) {
                _fansCountLabel.text = [NSString stringWithFormat:@"粉丝 %ld万", num / 10000];
            }
            else
            {
                _fansCountLabel.text = [NSString stringWithFormat:@"粉丝 %.1f万", num / 10000.0];
            }
        }
        _ptitleLabel.text = searchModel.personDescribe;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
